<?
ini_set('display_errors',1);
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
function getndraw_cats($nid)
{
$query=db_select('node','n');
$query->leftJoin('field_revision_field_place_category','c','c.entity_id=n.nid');
$query->leftJoin('taxonomy_term_data','t','t.tid=c.field_place_category_tid');
$query->fields('t',array('tid','name'))
->condition('n.nid',$nid)->orderby('t.weight');
$result=$query->execute();
$out='';
while($r=$result->fetchObject())
	{
	$out.=l($r->name,'taxonomy/term/'.$r->tid)." ";
	
	}
	
return $out;
}
$query=db_select('node','n');
		$query->leftJoin('field_revision_field_place_city','c','c.entity_id=n.nid');
		$query->leftJoin('field_revision_field_place_address','a','a.entity_id=n.nid');
		$query->leftJoin('field_revision_field_place_phone','p','p.entity_id=n.nid');
		$query->leftJoin('field_revision_field_place_website','w','w.entity_id=n.nid');
	$query->leftJoin('field_revision_field_id_place_karabas','k','k.entity_id=n.nid');
	$query->leftJoin('field_revision_field_id_place_inetbilet','i','i.entity_id=n.nid');
	
		$query->leftJoin('citydomain','cc','cc.tid=c.field_place_city_tid');
		$query->fields('n',array('nid','title'))
		->fields('cc',array('name','url'))
		->fields('a',array('field_place_address_value'))
		->fields('p',array('field_place_phone_value'))
		->fields('w',array('field_place_website_value'))
		->fields('k',array('field_id_place_karabas_value'))
		->fields('i',array('field_id_place_inetbilet_value'))
		->condition('n.type','place')->orderby('n.title');
		$result=$query->execute();
		#print_r($query);
print "<table border=1 style='border-collapse:collapsed'>
<tr><th>Название</th><th>Город</th><th>Адрес</th><th>Телефон</th><th>Сайт</th><th>тип заведения</th><th>ID Карабас</th><th>ID И.Б.</th></tr>";		
while($r=$result->fetchObject())
	{
	print "<tr><td>".l($r->title,'node/'.$r->nid,array('attributes'=>array('target'=>'blank')))."</td>
	<td>".l($r->name,$r->url,array('attributes'=>array('target'=>'blank')))."</td>
	<td>".$r->field_place_address_value."</td>
	<td>".(!empty($r->field_place_phone_value)?$r->field_place_phone_value:'&nbsp;')."</td>
	<td>".(!empty($r->field_place_website_value)?$r->field_place_website_value:'&nbsp;')."</td>
	<td>".getndraw_cats($r->nid)."</td>
	<td>".(!empty($r->field_id_place_karabas_value)?$r->field_id_place_karabas_value:'&nbsp;')."</td>
	<td>".(!empty($r->field_id_place_inetbilet_value)?$r->field_id_place_inetbilet_value:'&nbsp;')."</td>
	</tr>";
#	print_r($r);
	}
print "</table>";		

#$query=db_select('field_revision_field_karabas','fk')->fields('fk')->condition('fk.field_karabas_value',(int)$item->EventId)->execute()->fetchAssoc();
die("done<hr>");
?>